package cn.qf.first.controller;

import cn.qf.first.entity.Shop;
import cn.qf.first.exceptions.BaseException;
import cn.qf.first.pojo.vo.RespVo;
import cn.qf.first.service.OrderService;
import cn.qf.first.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @date: 2021/6/25 17:56
 * @description:
 */

@Api(tags = "商家业务")
@RestController
@RequestMapping("/shop")
public class ShopController extends BaseController {

    @Autowired
    private ShopService shopService;

    @ApiOperation("获取商户信息")
    @GetMapping("/getShop")
    public List<Shop> getShop(){
        List<Shop> shop = shopService.selectShop();
        System.out.println(shop);
        if(shop == null){
            throw new BaseException(RespVo.CodeType.FAil.getValue(),"错误");
        }
        return shop;
    }

    @ApiOperation("根据商户名获取商户信息")
    @GetMapping("/getShopByName")
    public List<Shop> getShopByName(String shopName){
        List<Shop> shop = shopService.selectShopByName(shopName);
        System.out.println(shop);
        if(shop == null){
            throw new BaseException(RespVo.CodeType.FAil.getValue(),"错误");
        }
        return shop;
    }


    @ApiOperation("根据商户id删除商户")
    @GetMapping("/delectShopById")
    public int delectShopById(Long shop_id){
        int i = shopService.delectShopById(shop_id);
        System.out.println(i);
        if(i == 0){
            throw new BaseException(RespVo.CodeType.FAil.getValue(),"错误");
        }
        return i;
    }
}
